package easy;

import org.junit.Test;

import java.util.Arrays;
import java.util.List;

public class a119_杨辉三角2 {
    /*public List<Integer> getRow(int rowIndex) {
        List<Integer> list = new ArrayList<>();
        int[] ints = new int[rowIndex + 1];
        for (int i = 0; i <= rowIndex; i++) {
            int last = 1;
            for (int n = 0; n <= i; n++) {
                if (n == 0 || n == i) {
                    ints[n] = 1;
                } else {
                    int l = last;
                    int r = ints[n];
                    last = r;
                    ints[n] = l + r;
                }
            }
        }
        for (int i : ints) {
            list.add(i);
        }
        return list;
    }*/

    public List<Integer> getRow(int rowIndex) {
        List<Integer> list = Arrays.asList(new Integer[rowIndex + 1]);
        for (int i = 0; i <= rowIndex; i++) {
            int last = 1;
            for (int n = 0; n <= i; n++) {
                if (n == 0 || n == i) {
                    list.set(n, 1);
                } else {
                    int l = last;
                    int r = list.get(n);
                    last = r;
                    list.set(n, l + r);
                }
            }
        }
        return list;
    }
    @Test
    public void test(){
        getRow(3);
    }
}
